#ifndef LISTTABLEMODEL_H
#define LISTTABLEMODEL_H

#include <QObject>
#include <QAbstractTableModel>
#include <QDateTime>
#include <QHash>

class ListTableModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    Q_ENUMS(DATA_ROLE)
    enum DATA_ROLE {
        Role_is_selected = Qt::UserRole + 1,
        Role_order_num,
        Role_product_name,
        Role_product_total,
        Role_product_price,
        Role_join_time
    };

public:
    ListTableModel(QObject *parent = nullptr);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    QHash<int, QByteArray> roleNames() const override;
    QVariant data(const QModelIndex &index, int role) const override;
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;

    void parseJsonData(QString filePath);
    Q_INVOKABLE void remove(int row);

private:
    struct OrderData {
        bool is_selected;
        QString order_num;
        QString product_name;
        int product_total;
        qreal product_price;
        QDateTime join_time;
    };
    QStringList headers;
    QVector<OrderData> vDatas;
};

#endif // LISTTABLEMODEL_H
